<%@ page import="cn.estore.dao.CustomerDao" %>
<%@ page import="cn.estore.entity.CustomerEntity" %><%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2023/12/19
  Time: 8:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<div align="center">
    <%
        //用户登录
        CustomerDao dao=new CustomerDao();
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        CustomerEntity userEntity=dao.selectCustomerEntity(name);
        if (userEntity==null||userEntity.equals("")){//当前登录用户名不存在

    %>
    <script language="JavaScript">
        alert('不存在该用户,请重新登录!!!');
        history.go(-1);
    </script>
    <%}else {//存在该用户，将密码取出来比对
            if (!userEntity.getPassword().equals(password)){


    %>

    <script language="JavaScript">
        alert('密码错误,请重新登录')
    history.go(-1);
    </script>
    <%}else {//用户名与数据库密码一直，为授权用户，保存信息至session
                session.setAttribute("user",userEntity);
                session.setAttribute("name",name);
            %>

    <script language="JavaScript">
        window.location.href='<%=request.getContextPath()%>/pages/product/main.jsp';
    </script>
    <%}}%>
    }
</div>
</body>
</html>
